﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraCharts;

namespace RemoteImaging.FaceCapture
{
    using RemoteImaging.LicensePlate;
    public partial class FormReport : DevExpress.XtraEditors.XtraForm
    {
        public FormReport()
        {
            InitializeComponent();
        }

        private void exportToExcel_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                this.chartControl1.ExportToImage(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);

            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {

            XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
            diagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
            diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Day;
            diagram.AxisX.DateTimeOptions.Format = DateTimeFormat.MonthAndDay;

        }


        private void chartControl1_MouseClick(object sender, MouseEventArgs e)
        {
            var hi = chartControl1.CalcHitInfo(e.Location);

            var sp = hi.SeriesPoint;
            if (sp != null)
            {
                var arg = sp.DateTimeArgument;

                if (chartControl1.Series[0].Visible == true)
                {
                    chartControl1.Series[0].Visible = false;
                    chartControl1.Series[1].Visible = true;


                    SetAxisFormat(DateTimeMeasurementUnit.Day);

                    chartControl1.Series[1].DataFilters[0].Value = arg.AddDays(-arg.Day);
                    chartControl1.Series[1].DataFilters[1].Value = arg.AddDays(-arg.Day).AddMonths(1);
                    chartControl1.Titles[0].Visible = true;
                    chartControl1.Titles[1].Text = "人流量天统计图";


                }
            }

            var link = hi.ChartTitle;
            if (link != null && link.Text.Contains("返回"))
            {
                chartControl1.Series[0].Visible = true;
                chartControl1.Series[1].Visible = false;

                SetAxisFormat(DateTimeMeasurementUnit.Month);

                link.Visible = false;
                chartControl1.Titles[1].Text = "人流量月统计图";
            }

        }
        private void SetAxisFormat(DateTimeMeasurementUnit unit)
        {
            XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
            diagram.AxisX.DateTimeMeasureUnit = unit;
            diagram.AxisX.DateTimeGridAlignment = unit;
            diagram.AxisX.DateTimeOptions.Format = unit == DateTimeMeasurementUnit.Day ? DateTimeFormat.MonthAndDay : DateTimeFormat.MonthAndYear;

            diagram.AxisX.Label.Angle = unit == DateTimeMeasurementUnit.Day ? -45 : 0;
            diagram.AxisX.Label.Antialiasing = true;

        }
    }
}